package se.gtg.einstein;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class EcoAppActivity extends Activity implements OnClickListener {
	SearchLists lists = new SearchLists();
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button btn = (Button) findViewById(R.id.btnSearch);
		btn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		lists.clear();
		EditText search = (EditText) findViewById(R.id.searchText);
		String[] searchString = search.getText().toString().split("\n");

		for (String searchWord : searchString) {
			searchWord = searchWord.toLowerCase();
			SearchList list = new SearchList(searchWord);
			
			for (String[] record : table) {
				int found = record[0].toLowerCase().indexOf(searchWord);
				
				if (found >= 0){
					list.add(record[0], record[1]);
				}
			}
			lists.add(list);
		}

		EcoApp ecoApp = (EcoApp)getApplicationContext();
		ecoApp.setSearchLists(lists);

		if (lists.hasDoublets()){
			Intent doublets = new Intent(this,DoubletsActivity.class);
			this.startActivity(doublets);
		}else{
			Intent showResult = new Intent(this,ShowResultActivity.class);
			this.startActivity(showResult);
		}
	}
	String[][] table=new String[][]{
			{"Alpro Sojadryck 1000mm", "18.95"},
			{"Standardmjölk Arla 1L", "9.95"},
			{"Mellanmjölk Arla 1L", "9.95"},
			{"Milda yoghurt 1L", "17.95"},
			{"A-Fil hallon 1L", "16.95"},
			{"A-Fil 1L", "15.95"},
			{"Filmjölk 1L", "11.95"},
			{"A-Lättfil 1L", "12.95"},
			{"Lättmjölk Arla 0.3L", "8.95"},
			{"Mellanmjölk Arla 0.3L", "8.95"},
			{"Mellanmjölk 1.5L Arla", "13.95"},
			{"Standardmjölk 0.33L Arla", "4.95"},
			{"Mild lätt yoghurt Arla 1L", "17.95"},
			{"Vispgrädde Arla 0.3L", "11.95"},
			{"Gammaldags mjölk Arla 1L", "11.95"},
			{"Matlagnings grädde Arla 0.25L", "10.95"},
			{"Grädde Arla 0.5L", "21.95"},
			{"Gräddfil Arla  0.3L", "9.95"},
			{"Creme Fraiche Arla 0.2L", "9.95"},
			{"Bregott 300g", "20.95"},
			{"Bregott matfett 600g", "36.95"},
			{"Fjällfil 1L", "15.95"},
			{"Fjällyoghurt 1L", "18.95"},
			{"Ägg sexpack", "17.95"},
			{"Yoghurt Hallon/vanilj 1L", "20.95"},
			{"Flytande margarin 0.5L", "16.95"},
			{"Gräddfil ICA 0.3L", "9.95"},
			{"Ägg 10pack ICA", "28.95"},
			{"Keso Arla 250g", "13.95"},
			{"Keso Arla 500g", "24.95"},
			{"Turkisk youghurt 1000g", "23.95"},
			{"Milda margarin 250g", "15.95"},
			{"Havredryck 1L", "13.95"},
			{"Sojagrädde spray 250", "22.95"},
			{"Smör med salt 500g", "34.95"},
			{"Smör 250g", "20.95"},
			{"Laktos fri matlagningsgrädde Valio 0.2L", "10.95"},
			{"Laktos fri mellanmjölk Valio 1L", "19.95"},
			{"Laktos fri vispgrädde Valio 0.2L", "12.95"},
			{"Yoghurt Yoggi 4x125g", "14.95"},
			{"Yoghurt Yoggi 500g", "14.95"},
			{"Yoghurt 1000g", "19.95"},
			{"Vitlök Eko", "109.75"},
			{"ICA eko banan", "22.95"},
			{"Svamp Shi-Take", "199"},
			{"Rödlök Eko", "37.90"},
			{"Apelsin nät Eko", "32.95"},
			{"Päron Eko", "39.90"},
			{"Kastanjechampinjoner", "131.80"},
			{"Gul lök Eko", "31.90"},
			{"Plommon urkärnade", "109.75"},
			{"Dadlar urkärnade", "119.75"},
			{"Fikon", "149.75"},
			{"Sallad endive Eko", "111.80"},
			{"Citron Eko", "62.71"},
			{"Paprika spetsig", "187.94"},
			{"Paprika Röd/Gul", "89.83"},
			{"Kiwi korg", "39.90"},
			{"Äpple Eko Röd", "39.91"},
			{"Morot Eko", "17.95"},
			{"Hasselnötter Eko", "249.38"},
			{"Solroskärnor Eko", "161.88"},
			{"Tranbär Eko", "336.88"},
			{"Färsk mynta Eko st", "23.95"},
			{"Gurka Eko", "59.95"},
			{"Tomat cocktail Eko", "87.80"},
			{"Alfagrodd", "130.38"},
			{"Vitkål", "18.95"},
			{"Broccoli", "52.95"},
			{"Potatis Eko", "18.48"},
			{"Rödbeta Eko", "19.95"},
			{"Fransk Dragon st", "23.95"},
			{"Timjan", "16.95st"},
			{"Koriander st", "16.95"},
			{"Basilika st", "16.95"},
			{"Rädisalfagrodd", "130.38"},
			{"Persilja st", "14.95"},
			{"Oregano st", "16.95"},
			{"Citronmeliss", "16.95"},
			{"Salvia", "16.95"},
			{"Rosmarin", "23.95"},
			{"Sötpotatis", "26.95"}
	};
	
}